{% extends "announcements/announcements.html" %}

{% block page_link %}
    <script src="../../static/announcements/js/newly.js"></script>
    <link rel="stylesheet" href="../../static/announcements/css/style.css">
    <link rel="stylesheet" href="../../static/system_setup/css/style.css">
    <script type="text/javascript" charset="utf-8" src="../../static/announcements/ueditor/1.4.3/ueditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="../../static/announcements/ueditor/1.4.3/ueditor.all.min.js"></script>
    <script type="text/javascript" charset="utf-8" src="../../static/announcements/ueditor/1.4.3/lang/zh-cn/zh-cn.js"></script>
    <link rel="stylesheet" href="../../static/public_file/css/PersonnelChooser.css">
{% endblock %}


{% block style %}
    <style>
        .add_class {
            background: #1E90FF;
        }

        .add_background {
            background: #A9A9A9;
        }

        tr th {
            height: 35px;
            text-align: center;
        }

        .li-class {
            list-style: none;
            margin-top: 2%;
            color: #0b0b0b;
            cursor: pointer;
        }

        .switch-btn {
            cursor: pointer;
            width: 50px;
            height: 25px;
            position: relative;
            border: 1px solid #dfdfdf;
            background-color: #CFCFCF;
            box-shadow: #dfdfdf 0 0 0 0 inset;
            border-radius: 15px;
            background-clip: content-box;
            display: inline-block;
            -webkit-appearance: none;
            user-select: none;
            outline: none;
        }

        .switch-btn:before {
            content: '';
            width: 23px;
            height: 23px;
            position: absolute;
            top: 0;
            left: 0;
            border-radius: 20px;
            background-color: #fff;
            box-shadow: 0 1px 3px rgba(0, 0, 0, .4);
        }

        .switch-btn:checked {
            border-color: #56b0d4;
            box-shadow: #56b0d4 0 0 0 16px inset;
            background-color: #56b0d4;
        }

        .switch-btn:checked:before {
            left: 26px;
        }

        .switch-btn.switch-btn-animbg {
            transition: background-color ease .4s;
        }

        .switch-btn.switch-btn-animbg:before {
            transition: left .3s;
        }

        .switch-btn.switch-btn-animbg:checked {
            box-shadow: #dfdfdf 0 0 0 0 inset;
            background-color: #56b0d4;
            transition: border-color .4s, background-color ease .4s;
        }

        .switch-btn.switch-btn-animbg:checked:before {
            transition: left .3s;
        }

        .file {
            position: relative;
            display: inline-block;
            background: #D0EEFF;
            border: 1px solid #99D3F5;
            border-radius: 4px;
            padding: 4px 12px;
            overflow: hidden;
            color: #1E88C7;
            text-decoration: none;
            text-indent: 0;
            line-height: 20px;
        }

        .file input {
            position: absolute;
            font-size: 100px;
            right: 0;
            top: 0;
            opacity: 0;
        }

        .file:hover {
            background: #AADFFD;
            border-color: #78C3F3;
            color: #004974;
            text-decoration: none;
        }

        input {
            padding: 8px 10px 8px 40px;
        }

        .search {
            width: 300px;
            display: flex;
            float: right;
            margin: 10px 0;
            margin-right: 1%;
            /*border: 1px solid red;*/
        }

        .search input {
            vertical-align: middle;
            float: left;
        / / 左浮动 flex: 4;
            height: 30px;
            width: 230px;
            outline: none;
            border: 1px solid #0070c1;
            box-sizing: border-box;
        / / 盒子模型，怪异IE盒子模型，width = content + border * 2 + padding * 2 padding-left: 10 px;
            border-bottom-left-radius: 3px;
            border-top-left-radius: 3px;
        }

        .search button {
            float: right;
            flex: 1;
            height: 30px;
            width: 70px;
            line-height: 30px;
            background-color: #0070c1;
            color: white;
            border-style: none;
            outline: none;
            border-bottom-right-radius: 3px;
            border-top-right-radius: 3px;
        }

        .search button i {
            font-style: normal;
        }

        .search button:hover {
            font-size: 16px;
        }

        #addForm {
            width: 800px;
            height: 620px;
            background: #F5F5F5;
            position: absolute;
            border: #dfdfdf solid 1px;
            margin: auto;
            border-radius: 3px;
            top: 50%;
            left: 50%;
            /* 实现鼠标拖拽使用css3效果 */
            transform: translate(-50%, -50%);
            display: none;
            z-index: 10100;
            font-size: 0;
        }

        /* 标题 */
        #title {
            display: flex;
            justify-content: space-between;
            box-sizing: border-box;
            padding: 0 10px;
            height: 50px;
            color: #0b0b0b;
            cursor: move;
            /*border: #dfdfdf solid 1px;*/
            width: 100%;
            background: #f4f7fa;
            border-top-left-radius: 5px;
            border-top-right-radius: 5px;
        }

        .top_tag {
            border-bottom: #01AAED solid 2px;
            color: #01AAED;
        }

        .tab_top {
            width: 100px;
            height: 40px;
            line-height: 40px;
            text-align: center;
            display: inline-block;
            cursor: pointer;
        }

        #ThreeNavigation div {
            padding-left: 2%;
        }
    </style>
{% endblock %}


{% block right_content %}
    <div class="headline">
        <div id="document_addressee_details_tab" onclick="change_mind('add_jurisdiction')" class="tab_top">
            新增公告
        </div>
        <div style="width: 7%;text-align: center;height: 100%;line-height: 40px;float: right;">
            <button style="height: 30px;width: 90%;background: #0070c1;color: #ffffff;border-radius: 3px" id="add_station" type="button"
                    class="btn btn-default add-station" onclick="get_content()">提交
            </button>
        </div>
    </div>

    <div id="add_jurisdiction" style="width: 100%;height: 95%;overflow: auto;background-color: white;padding-left: 3%;">
        <div style="margin-top: 3%;width: 100%;">
            <span style="color: red;">*</span>
            <label> 公告标题：</label>
            <input id="cement-name" class="form-control section-input" type="text" placeholder="标题"
                   style="width: 80%;padding-left: 1%;">
        </div>

        <div style="margin-top: 2%;width: 100%;">
            <div style="display: inline-block;width: 45%;">
                <span style="color: red;visibility: hidden;">*</span>
                <label> 发布部门：</label>
                <input id="department" type="text" value="{{ department }}"
                       style="height: 35px;border-radius: 3px;border: 1px solid #d7dbda;padding-left: 1%;width: 70%;"
                       disabled>
            </div>
            <div style="display: inline-block;width: 48%;">
                <span style="color: red;visibility: hidden;">*</span>
                <label> 发布人：</label>
                <input id="realname" type="text" value="{{ realname }}"
                       style="height: 35px;border-radius: 3px;border: 1px solid #d7dbda;padding-left: 1%;width: 75%;"
                       disabled>
            </div>
        </div>

        <div>
            <div style="margin-top: 2%;width: 45%; display: inline-block;">
                <span style="color: red;vertical-align: top;">*</span>
                <label style="vertical-align: top;"> 是否全院发送：</label>
                <div class="custom-control custom-switch custom-switch-text custom-control-inline">
                    <div class="custom-switch-inner" style="width: 60px;">
                        <label><input id="switch" onclick="public_OR_not()" class="switch-btn switch-btn-animbg"
                                      type="checkbox" checked></label>
                    </div>
                </div>
            </div>

            <div style="width: 48%; display: inline-block;">
                <label> 分管领导：</label>
                <select id="fg_people" class="form-control section-input" style="width: 75%;">
                    {% for leader in leaders %}
                        <option value="{{ leader.id }}">{{ leader.real_name }}</option>
                    {% endfor %}
                </select>
            </div>
        </div>

        <div id="receive" style="width: 100%;display: none;margin-top: 2%;">
            <span style="color: red;">*</span>
            <label> 接&nbsp;收&nbsp;人&nbsp;：</label>
            <input onclick="model_line()" id="recipient" class="form-control section-input" type="text" style="width: 80%;">
        </div>

        <div id="receive_content" style="width: 100%;margin-top: 2%;">
            <span style="color: red;">*</span>
            <label style="vertical-align: top;"> 公告内容：</label>

            <iframe id="view_iframe" src="home.html"
                    style="display: inline-block;border: none;vertical-align: top;width: 81%;height: 700px;"></iframe>
        </div>

        <div style="margin-top: 2%;width: 100%;">
            <span style="color: red;visibility: hidden;">*</span>
            <label style="vertical-align: top;"> 附&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;件：</label>
            <a href="javascript:;" class="file" style="display: inline-block;vertical-align: top;">
                上传附件
                <input type="file" name="accessory" id="accessory" onchange="upload_accessory()">
            </a>
        </div>

        <div style="margin-top: 2%;width: 100%;">
            <span style="color: red;visibility: hidden;">*</span>
            <div style="border: #00d0ff solid 1px;display: inline-block;vertical-align: top;width: 86%;">
                <table class="table table-hover table-bordered" style="border-collapse: collapse;width: 100%;">
                    <thead>
                    <tr>
                        <th scope="col" style="width: 8%;">序号</th>
                        <th scope="col" style="width: 30%;">文件名称</th>
                        <th scope="col" style="width: 8%;">文件大小</th>
                        <th scope="col" style="width: 15%;">上传时间</th>
                        <th scope="col" style="width: 10%;">上传人员</th>
                        <th scope="col" style="width: 5%;">操作</th>
                    </tr>
                    </thead>
                    <tbody style="overflow: auto;" id="t_table_1"></tbody>
                </table>
            </div>
        </div>

        <div style="height: 50px;">

        </div>
    </div>


    <div id="staff-select" class="shade">
        <div id="staff-model" style="width: 100%;height: 100%;position: absolute;">
            <div style="width: 900px;height: 500px;background: #F5F5F5;z-index: 10000;position: absolute;top: 50%;left: 50%;transform:translate(-50%,-50%);border-radius: 3px;border: #dfdfdf solid 1px;">
                <div id="staff-box" style="width: 100%;height: 40px;background: #f4f7fa;cursor: move;border-top-left-radius: 5px;border-top-right-radius: 5px;border-bottom: #dfdfdf solid 1px;">
                    <div style="width: 20%;margin-left: 1%;display: inline-block;line-height: 40px;font-size: 14px;">
                        选择人员
                    </div>
                    <span onclick="close_model()" style="float: right;padding-right: 2%;cursor: pointer;line-height: 37px;">
                        <i class="iconfont icon-quchu"></i>
                    </span>
                </div>
                <div style="height: 460px;width: 100%;border-bottom: #dfdfdf solid 1px;">
                    <div style="width: 70px;height: 100%;border-right: #cfcfcf solid 1px;display: inline-block;vertical-align: top;">
                        <div id="dep" class="navigation navigation_color" onclick="change_navigation(this)">部门</div>
                        <div id="limits" class="navigation" onclick="change_navigation(this)">权限</div>
                        <div id="fun" class="navigation" onclick="change_navigation(this)">职能</div>
                    </div>
                    <div style="width: 200px;height: 100%;border-right: #cfcfcf solid 1px;display: inline-block;vertical-align: top;">
                        <div style="width: 100%;height: 50px;line-height: 50px;">
                            <input id="SearchDep" onkeydown="SearchDepartment()" class="search_input" type="text" placeholder="搜索" autocomplete="off" style="width: 95%;">
                        </div>
                        <div id="SecondaryNavigation" style="width: 100%;height: 403px;line-height: 50px;overflow: auto;"></div>
                    </div>
                    <div style="width: 200px;height: 100%;border-right: #cfcfcf solid 1px;display: inline-block;vertical-align: top;">
                        <div style="width: 100%;height: 50px;line-height: 50px;padding-left: 2%;">
                            <input type="checkbox" id="select-all" onclick="SelectAll(this)">
                            <input id="SearchPeo" onkeydown="SearchProple()" class="search_input" type="text" placeholder="搜索" autocomplete="off" style="width: 87%;">
                        </div>
                        <div id="ThreeNavigation" style="width: 100%;height: 403px;line-height: 50px;overflow: auto;"></div>
                    </div>
                    <div style="width: 410px;height: 100%;display: inline-block;vertical-align: top;overflow: auto">
                        <div style="width: 100%;height: 40px;text-align: left;font-size: 14px;line-height: 40px;">
                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;已选 <span id="selected-number">0</span> 人
                        </div>
                        <div id="selected-div" style="width: 100%;font-size: 14px;height: 370px;overflow: auto;line-height: 20px;">

                        </div>
                        <div style="width: 100%;font-size: 14px;height: 40px;text-align: center;">
                            <button onclick="IdentifyPersonnel()" style="width: 100px;height: 30px;line-height: 25px;text-align: center;letter-spacing: 5px;border-radius: 3px;border: #cfcfcf solid 1px;font-size: 14px;cursor: pointer;margin-top: 10px;">完成</button>
                            <button onclick="close_model()" style="margin-left: 15px;width: 100px;height: 30px;line-height: 25px;text-align: center;color: #0abb78;letter-spacing: 5px;border-radius: 3px;font-size: 14px;border: #cfcfcf solid 1px;cursor: pointer;margin-top: 10px;">取消</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div id="del_adjunct"
         style="z-index: 1000;position: fixed;background-color: rgba(36, 36, 36, 0.5);width: 100%;height: 100%;top: 0;left: 0;right: 0;bottom: 0;display: none;">
        <div style="top: 50%;left: 50%;width: 400px;height: 150px;background: white;transform:translate(-50%,-50%);border: #dfdfdf solid 1px;position: absolute;border-radius: 4px;">
            <div style="width: 100%;height: 100px;text-align: center;line-height: 100px;">请查看附件，删除无用的附件！</div>
            <hr>
            <div style="width: 100%;height: 50px;text-align: right;padding-right: 5%;">
                <button onclick="del_adjunct_button()"
                        style="width: 50px;height: 30px;line-height: 30px;margin-top: 10px;background: #00a0e9;color: white;border-radius: 4px;border: #00a0e9 solid 1px;">
                    确认
                </button>
            </div>
        </div>
    </div>
{% endblock %}




{% block script %}
    <script type="text/javascript" src="../../static/public_file/js/PersonnelChoosersNew.js" charset="gb2312"></script>
    <script>
        window.onload = function () {
            document.getElementById("loading").style.display = "none";
            document.getElementById("Announcement-management").className = "add_class";
            document.getElementById("inform").className = "add-nav-active";
        };
        var uuid_str = "{{ uuid | safe }}";

        // 获取是否公开
        function public_OR_not() {
            if (document.getElementById("switch").checked) {
                document.getElementById("receive").style.display = "none";
            } else {
                document.getElementById("receive").style.display = "inline-block";
            }
        }

        function del_adjunct_button() {
            document.getElementById("del_adjunct").style.display = 'none';
        }

        function change_mind(ele_id) {
            if (ele_id === "jurisdiction_list") {
                document.getElementById("jurisdiction_list").style.display = "inline-block";
                document.getElementById("add_jurisdiction").style.display = "none";
                document.getElementById("dispatch_detail_tab").className = "tab_top top_tag";
                document.getElementById("document_addressee_details_tab").className = "tab_top";
                document.getElementById("add_station").style.display = "none";
            } else {
                document.getElementById("add_jurisdiction").style.display = "inline-block";
                document.getElementById("jurisdiction_list").style.display = "none";
                document.getElementById("dispatch_detail_tab").className = "tab_top";
                document.getElementById("document_addressee_details_tab").className = "tab_top top_tag";
                document.getElementById("add_station").style.display = "inline-block";
            }
        }

        // 删除列表
        function deltr() {
            var tb = document.getElementById('t_table');
            var rowNum = tb.rows.length;
            for (i = 0; i < rowNum; i++) {
                tb.deleteRow(i);
                rowNum = rowNum - 1;
                i = i - 1;
            }
        }

        var view_iframe = document.getElementById('view_iframe').contentWindow;

        function get_content() {
            document.getElementById("loading").style.display = "inline-block";
            var content = view_iframe.UE.getEditor('editor').getContent();

            var names = document.getElementById("cement-name").value;             // 公告标题
            var department = document.getElementById("department").value;               // 发布部门
            var realname = document.getElementById("realname").value;                   // 发布人
            var recipient = document.getElementById("recipient").value;                   // 接收人

            var switch_s = "";
            if (document.getElementById("switch").checked) {
                switch_s = "公开";
            } else {
                switch_s = "不公开";
            }
            var myselect = document.getElementById("fg_people");
            var index = myselect.selectedIndex;
            var fg_people = myselect.options[index].value;

            var xhr = new XMLHttpRequest();
            var local_host = window.location.host;          // 获取当前IP
            xhr.open('post', "/announcements/notice_index", true);
            xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
            var encode = encodeURI(content);
            // 对编码的字符串转化base64
            var base64 = btoa(encode);
            xhr.send("content=" + base64 + "&name=" + names + "&department=" + department + "&realname=" + realname + "&recipient=" + recipient + "&switchs=" + switch_s + "&fg_people=" + fg_people + "&uuid=" + String(uuid_str));
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4) {
                    if (xhr.status === 200) {
                        document.getElementById("loading").style.display = "none";
                        var JsonDate = JSON.parse(xhr.responseText);
                        if (JsonDate['code'] !== 200) {
                            alert(JsonDate['message'])
                        } else {
                            alert(JsonDate['message']);
                            window.location.href = 'MyAnnouncementList.html'
                        }
                    }
                }
            };
        }

        // 上传附件
        function upload_accessory() {
            var form = new FormData();
            var files = document.getElementById("accessory").files[0];
            form.append("file1", files);
            form.append('number', uuid_str);
            form.append('source', "tz");

            var xhr = new XMLHttpRequest();
            var local_host = window.location.host;          // 获取当前IP
            xhr.open('post', "/administrative/topics_attachments_upload", true);
            xhr.send(form);
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4) {
                    if (xhr.status === 200) {
                        document.getElementById("loading").style.display = "none";
                        var JsonDate = JSON.parse(xhr.responseText);
                        console.log(JsonDate);
                        creat_table(JsonDate, "t_table_1")
                        document.getElementById("accessory").value = "";
                    }
                }
            };
        }


        // 创建附件列表
        function creat_table(JsonData, tbody_id) {
            var t_table = document.getElementById(tbody_id);
            var local_host = window.location.host;
            if (Array.isArray(JsonData["pdf_path"])) {
                for (var i = 0; i < JsonData["pdf_path"].length; i++) {
                    var tr = document.createElement("tr");var td1 = document.createElement("td");var td2 = document.createElement("td");var td3 = document.createElement("td");var td4 = document.createElement("td");var td5 = document.createElement("td");var td6 = document.createElement("td");
                    td1.innerHTML = t_table.children.length + 1;td1.style.textAlign = "center";td1.style.border = "#cccccc solid 1px";td1.style.borderTop = "none";
                    td2.innerHTML = JsonData["file_name"];td2.style.paddingLeft = "1%";td2.style.border = "#cccccc solid 1px";td2.style.borderLeft = "none";td2.style.borderTop = "none";
                    td3.innerHTML = JsonData["file_size"];td3.style.textAlign = "center";td3.style.border = "#cccccc solid 1px";td3.style.borderLeft = "none";td3.style.borderTop = "none";
                    td4.innerHTML = JsonData["upload_time"];td4.style.textAlign = "center";td4.style.border = "#cccccc solid 1px";td4.style.borderLeft = "none";td4.style.borderTop = "none";
                    td5.innerHTML = JsonData["uploader"];td5.style.textAlign = "center";td5.style.border = "#cccccc solid 1px";td5.style.borderLeft = "none";td5.style.borderTop = "none";
                    td6.innerHTML = "<a target='_blank' href='" + JsonData["pdf_path"][i]["pdf_path"] + "'>查看</a> | <a style='color: red;' href='#' onclick='RemoveTr(this, \"" + tbody_id + "\", \"" + JsonData["pdf_path"][i]["id"] + "\")'>删除</a>";
                    td6.style.textAlign = "center";td6.style.border = "#cccccc solid 1px";td6.style.borderLeft = "none";td6.style.borderTop = "none";
                    tr.appendChild(td1);tr.appendChild(td2);tr.appendChild(td3);tr.appendChild(td4);tr.appendChild(td5);tr.appendChild(td6);t_table.appendChild(tr);
                }
                if (JsonData["pdf_path"].length > 1) {
                    document.getElementById("del_adjunct").style.display = 'block';
                }
            } else {
                tr = document.createElement("tr");td1 = document.createElement("td");td2 = document.createElement("td");td3 = document.createElement("td");td4 = document.createElement("td");td5 = document.createElement("td");td6 = document.createElement("td");
                td1.innerHTML = t_table.children.length + 1;td1.style.textAlign = "center";td1.style.border = "#cccccc solid 1px";td1.style.borderTop = "none";
                td2.innerHTML = JsonData["file_name"];td2.style.paddingLeft = "1%";td2.style.border = "#cccccc solid 1px";td2.style.borderLeft = "none";td2.style.borderTop = "none";
                td3.innerHTML = JsonData["file_size"];td3.style.textAlign = "center";td3.style.border = "#cccccc solid 1px";td3.style.borderLeft = "none";td3.style.borderTop = "none";
                td4.innerHTML = JsonData["upload_time"];td4.style.textAlign = "center";td4.style.border = "#cccccc solid 1px";td4.style.borderLeft = "none";td4.style.borderTop = "none";
                td5.innerHTML = JsonData["uploader"];td5.style.textAlign = "center";td5.style.border = "#cccccc solid 1px";td5.style.borderLeft = "none";td5.style.borderTop = "none";
                td6.innerHTML = "<a target='_blank' href='" + JsonData["pdf_path"] + "'>查看</a> | <a style='color: red;' href='#' onclick='RemoveTr(this, \"" + tbody_id + "\", \"" + JsonData["id"] + "\")'>删除</a>";
                td6.style.textAlign = "center";td6.style.border = "#cccccc solid 1px";td6.style.borderLeft = "none";td6.style.borderTop = "none";
                tr.appendChild(td1);tr.appendChild(td2);tr.appendChild(td3);tr.appendChild(td4);tr.appendChild(td5);tr.appendChild(td6);t_table.appendChild(tr);
            }
        }

        function RemoveTr(_this) {
            var table = document.getElementById("t_table_1");
            var trNode = $(_this).parent().parent();
            trNode.remove();

            for (var i = 0; i < table.children.length; i++) {
                table.children[i].children[0].innerHTML = i + 1;
            }

        }

        function scrollConversationScreen() {
            $('#selected-div').scrollTop($('#selected-div')[0].scrollHeight);
        }

        function IdentifyPersonnel() {
            var prople_list = [];
            var selected_personnel_list = document.getElementsByClassName('selected-personnel');
            for (var i=0; i<selected_personnel_list.length; i++) {
                prople_list.push(selected_personnel_list[i].innerText)
            }
            document.getElementById("recipient").value = prople_list.join();
            close_model()
        }
    </script>
{% endblock %}
